package com.longge;

import java.util.Stack;

public class DailyTemperatures {

    public int[] dailyTemperatures(int[] temperatures) {

        Stack<Integer> stack = new Stack<>();
        int[] res = new int[temperatures.length];
        for (int i = 0; i < temperatures.length; i++) {
            while (!stack.empty()&&temperatures[i] > temperatures[stack.peek()]) {
                    Integer preI = stack.pop();
                    res[preI] = i - preI;
            }
            stack.push(i);
        }
        return res;
    }

}
